package com.tbit.uqbike.webmanager.controller;

import com.github.pagehelper.PageInfo;
import com.tbit.common.utils.TraceUtil;
import com.tbit.uqbike.object.pojo.ReturnBikeLog;
import com.tbit.uqbike.object.pojo.dto.CommonDTO;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.ReturnBikeLogService;
import com.tbit.uqbike.webmanager.util.excel.ExcelUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author HZW
 * @ClassName ReturnBikeLogController
 * @Description
 * @date 2021/12/27 14:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/returnBikeLog")
public class ReturnBikeLogController extends BaseController {
    @Resource
    private ReturnBikeLogService returnBikeLogService;

    /**
     * 车辆详情的还车日志
     */
    @RequestMapping("/getInfo")
    public JsonResult getReturnBikeLog(CommonDTO commonDTO) {
        if (commonDTO.getUserCode() == null && commonDTO.getMachineNO() == null) {
            return JsonResult.fail("请输入设备编号或车辆编号", TraceUtil.getTraceIdByLocal());
        }
        startPage();
        List<ReturnBikeLog> list = returnBikeLogService.selectInfo(commonDTO);
        return JsonResult.ok(list, (int) new PageInfo<>(list).getTotal());
    }

    @PostMapping("/exportInfo")
    public Result exportInfo(@RequestBody CommonDTO commonDTO) {
        if (commonDTO.getUserCode() == null && commonDTO.getMachineNO() == null) {
            return Result.error("请输入设备编号或车辆编号");
        }
        List<ReturnBikeLog> list = returnBikeLogService.selectInfo(commonDTO);
        ExcelUtil<ReturnBikeLog> excel = new ExcelUtil<>(ReturnBikeLog.class);
        JsonResult jsonResult = excel.exportExcel(list, "还车日志");
        return Result.success(jsonResult.getData());
    }
}
